#include "../comm/logger.hpp"
#include "../comm/util.hpp"
#include "../comm/httplib.hpp"
#include "complie_run.hpp"

using namespace httplib;
using namespace ns_complie_run;

void useWay(const std::string& str){
    std::cout<<"UseWay:"<<std::endl;
    std::cout<<str<<"port"<<std::endl;
}

int main(int argc, char *argv[]){
    if(argc != 2){
        useWay(argv[0]);
        return 0;
    }
    Server ser;
    ser.Post("/compile_run",[](const Request &req, Response &resp){
       std::string in_json = req.body;
       std::string out_json;
       if( !in_json.empty() ){
        Complie_Run::complieAndRun(in_json,out_json);
        resp.set_content(out_json,"application/json;charset=utf-8");
       }
    });
    ser.listen("0.0.0.0",std::stoi(argv[1]));//启动http服务
    return 0;
    
}